package com.yunhai.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.tms.Store;
import com.yunhai.model.vo.tms.StoreAdd;
import com.yunhai.model.vo.tms.StoreQuery;
import com.yunhai.model.vo.tms.StoreUpdate;
import com.yunhai.store.service.StoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/store")
public class StoreController {

    @Resource
    private StoreService storeService;

    /**
     * 获取 Store 分页列表
     */
    @GetMapping("/pagination")
    public Ret getStorePagination(PaginationVo paginationVo, StoreQuery storeQuery ) throws Exception {
        IPage page = storeService.getStorePagination(paginationVo, storeQuery);
        return Ret.toPage(page);
    }


    /**
     * 获取 Store 详情
    */
   @GetMapping("/{id}")
   public Ret getStoreDetail(@PathVariable Long id) throws Exception {

       Store store = storeService.getStoreDetail(id);
       return Ret.ok(store);
   }


    /**
     * 新增 Store
     * */
    @PostMapping("")
    public Ret addStore(@RequestBody StoreAdd storeAdd) throws Exception {

        storeService.addStore(storeAdd);
        return Ret.ok();
    }


    /**
     * 更新 Store
     * */
    @PutMapping("")
    public Ret updateStore(@RequestBody StoreUpdate storeUpdate) throws Exception {

        storeService.updateStore(storeUpdate);
        return Ret.ok();
    }


    /**
     * 删除 Store
     * */
    @PostMapping("/batchRemove")
    public Ret batchRemoveStore( @RequestBody List<Long> ids ) throws Exception {

        storeService.batchRemoveStore(ids);
        return Ret.ok();
    }
}

  